package cn.edu.jxau.test;

import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;

public class Main {

	public static void main(String[] args) throws IOException {

		Main m = new Main();

		System.out.println(
				Arrays.deepToString(m.clearZero(new int[][] {{1,2,3},{0,1,2},{0,0,1}},3)));
	}

	public int[][] clearZero(int[][] mat, int n) {

		// 1.参数校验 //
		// 2.设置标记位 //
		boolean[] row = new boolean[mat.length];
		boolean[] column = new boolean[mat[0].length];
		for (int i = 0; i < mat.length; i++) {
			for (int j = 0; j < mat[0].length; j++) {
				if (mat[i][j] == 0) {
					row[i] = true;
					column[j] = true;
				}
			}
		}
		// 3.置0 //
		for (int i = 0; i < mat.length; i++) {
			for (int j = 0; j < mat[0].length; j++) {
				if (row[i] || column[j]) {
					mat[i][j] = 0;
				}
			}
		}
		return mat;
	}
}